<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/brython.css">

<link rel="stylesheet" href="console.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<script src="../tests/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="../tests/ace/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script src="../tests/ace/mode-python3.js" type="text/javascript" charset="utf-8"></script>
<script src="../tests/ace/snippets/python.js" type="text/javascript" charset="utf-8"></script>
</script>

<script type="text/javascript" src="../../src/brython_builtins.js"></script>
<script type="text/javascript" src="../../src/version_info.js"></script>
<script type="text/javascript" src="../../src/identifiers_re.js"></script>
<script type="text/javascript" src="../../src/py2js.js"></script>
<script type="text/javascript" src="../../src/py_object.js"></script>
<script type="text/javascript" src="../../src/py_type.js"></script>
<script type="text/javascript" src="../../src/py_utils.js"></script>
<script type="text/javascript" src="../../src/py_sort.js"></script>
<script type="text/javascript" src="../../src/py_builtin_functions.js"></script>
<script type="text/javascript" src="../../src/py_bytes.js"></script>
<script type="text/javascript" src="../../src/py_set.js"></script>
<script type="text/javascript" src="../../src/js_objects.js"></script>
<script type="text/javascript" src="../../src/stdlib_paths.js"></script>
<script type="text/javascript" src="../../src/py_import.js"></script>

<script type="text/javascript" src="../../src/py_string.js"></script>
<script type="text/javascript" src="../../src/py_int.js"></script>
<script type="text/javascript" src="../../src/py_float.js"></script>
<script type="text/javascript" src="../../src/py_complex.js"></script>
<script type="text/javascript" src="../../src/py_dict.js"></script>
<script type="text/javascript" src="../../src/py_list.js"></script>
<script type="text/javascript" src="../../src/py_generator.js"></script>
<script type="text/javascript" src="../../src/py_dom.js"></script>

<script type="text/javascript" src="../../src/builtin_modules.js"></script>
<script type="text/javascript" src="../src/py_import_hooks.js"></script>
<!-- script type="text/javascript" src="../src/async.js"></script -->

<script type="text/python3">
import json
from browser import window, ajax, html, document as doc
from javascript import JSConstructor
#from browser import console

def make_chart(data, brython_version):
    _div=html.DIV(id="chart_%s" % brython_version, style={'width': '800px', 'height': '400px'})
    doc['content'] <= _div

    _browsers=[_b for _b in data.keys() if _b is not None]
    _browsers.sort()          #sort does not work

    _series={}
    for _browser in _browsers:
        _tests=list(data[_browser].keys())
        _tests.sort()
        for _test in _tests:
            if _test not in _series:
               _series[_test]=[]
            _series[_test].append(data[_browser][_test]['avg'])

    #add number of submittals to end of browser name label
    _mycount={}
    for _browser in _browsers:
        _num=0
        for _test in data[_browser].keys():
            if data[_browser][_test]['count'] > _num:
               _num=data[_browser][_test]['count']

        _mycount[_browser]=_num

    _browser_count=['%s (%s)' % (_k, _v) for _k,_v in _mycount.items()]
    _browser_count.sort()
    
    _highchart = JSConstructor(window.Highcharts.Chart)
    _settings={
        'chart': {'renderTo': 'chart_%s' % brython_version, 'type':'bar'
        },
        'title': {'text': 'Brython vs CPython execution speed' % brython_version
        },
        'subtitle': {'text': 'Brython version %s' % brython_version},
        'yAxis': {
            'min': 0,
            'title': {
                'text': 'Brython X times faster',
                'align': 'high'
            },
            'labels': {
                'overflow': 'justify'
            },
            'plotLines': [{
                'dashStyle': 'Dot',
                'color': 'red',
                'value': '1',
                'width': '1',
                'zIndex': '100'
             }]
        },
        'tooltip': {
            'valueSuffix': ' times faster than CPython',
            'valueDecimals': 2
        },
        'plotOptions': {
            'bar': {'dataLabels': {'enabled': True,
                                   'format': '{y:.2f}'}}
        },
        'legend': {
            'layout': 'vertical',
            'align': 'right',
            'verticalAlign': 'top',
            'x': -40,
            'y': 100,
            'floating': True,
            'borderWidth': 1,
            'backgroundColor': '#FFFFFF',
            'shadow': True
        }
    }
    
    _settings['xAxis']= {
            'categories': _browser_count,
            'title': {'text': None}
    }

    
    _series1=[]
    _keys=list(_series.keys())
    _keys.sort()
    for _key in _keys:
        _series1.append({'name': _key, 'data': _series[_key]})

    _settings['series']= _series1
    
    _highchart(_settings)


def on_complete(*args):
    _json=json.loads(args[0].text)

    #lets make a chart for each brython version
    _brython_versions=list(_json.keys())
    _brython_versions.sort()
    _brython_versions.reverse()

    for _brython_version in _brython_versions:
        make_chart(_json[_brython_version], _brython_version)

def on_error(*args):
    doc['container'] <= html.PRE(args)

# upload results
req = ajax.ajax()
req.bind('complete', on_complete)
req.set_timeout(4, on_error)
req.open('GET', '//coherent-coder-88201.appspot.com/RequestData',True)
#req.open('GET', '//localhost:8080/RequestData',True)
req.set_header('content-type','application/x-www-form-urlencoded')
req.send()

</script>

<script type="text/python3">
from browser import document
import header

qs_lang,language = header.show()

# other translations

trans = {
    'report_bugs':{'en':'Please report bugs in the ',
                   'es':'Poner los bugs en el ',
                   'fr':"Signalez les bugs dans l'"},
    'test_page':{'en':'Tests page','es':'Página de pruebas','fr':'Page de tests'},
    'run':{'en':'run','es':'ejecutar','fr':'exécuter'},
    'clear':{'en':'clear','es':'borrar','fr':'effacer'}
}

for key in trans:
    if key in document:
        document[key].html = trans[key][language]

</script>

</head>
<body onload="brython({debug:1, cache:'none', static_stdlib_import:true})">

<table id=banner cellpadding=0 cellspacing=0>
<tr id=banner_row >
<td class="logo"><a href="../index.html"><img src="../brython.svg" class="logo"></a></td>
</tr>
</table>

</center>


<div id="content" style="width:1000px;height:100%">
</div>

</div>
</div>
</body>
</html>
